﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using Runda.CMS.Common.Utility;
using Runda.CMS.Bll;
using Runda.CMS.Common.Entity;

namespace Runda.CMS.Portal.SyncManage
{
    public partial class CustomerContactorList : BasePage
    {
        public Guid CustomerID
        {
            get
            {
                if (hiddenCustomerID.Value == string.Empty) return Guid.Empty;
                else return new Guid(hiddenCustomerID.Value);
            }
            set
            {
                hiddenCustomerID.Value = value.ToString();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["CustomerID"] != null)
                {
                    Data_Bind();
                    CustomerID = new Guid(Request.QueryString["CustomerID"]);
                }
            }
        }
        private void Data_Bind()
        {
            SysDictionaryBll sysDicBll = new SysDictionaryBll();

            List<WsmCustomerContactorEntity> lists = sysDicBll.GetAll<WsmCustomerContactorEntity>(" and ContactorID in (select ContactorID from Cms_Wsm_CustomerContactor where CustomerID = '" + Request.QueryString["CustomerID"] + "')");
            this.RepeaterParms.DataSource = lists;
            this.RepeaterParms.DataBind();

        }

        protected void delete(object sender, EventArgs e)
        {
            if (dicids.Value.Trim() != "")
            {
                string[] dicidsArray = dicids.Value.Trim().Split(new char[] { ';' });
                for (int index = 0; index < dicidsArray.Length; index++)
                {
                    SysDictionaryBll bll = new SysDictionaryBll();
                    WsmCustomerContactorEntity dicEntity = bll.Get<WsmCustomerContactorEntity>( new Guid(dicidsArray[index]).ToString());
                    bll.LogicDelete(dicEntity);                    
                }
                Data_Bind();
            }
        }

        protected void RepeaterParms_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "refersh")
            {
                Data_Bind();
            }
        }
    }
}
